Ext.define('Seq.grid.column.Refer', {
    extend: 'Ext.grid.column.Column',
    xtype: 'xrefercolumn',

    config: {
        url: undefined,
        fn: undefined,
        params: undefined, // Object或者返回Object的函数
    },
    valueField: 'name',

    width: 160,
    menuDisabled: true,

    renderer(value, metaData, record, rowIndex, colIndex, store, view) {
        let text = value, column = metaData.column;
        if (Ext.isObject(value)) { // 支持对象字段
            text = value ? value[column.valueField] : '';
        }
        if (!Ext.isEmpty(column.url)) {
            text = Ext.String.format('<a href="{0}">{1}</a>', column.url, text);
        } else if (column.fn) {
            let params = column.params;
            if (Ext.isFunction(params)) { // 函数
                params = params(record)
            } else if (Ext.isString(params)) { // 定义在controller里面的字符串
                var controller = Ext.getCmp(view.getId()).up('[controller]').getController();
                params = Ext.callback(controller[params], controller, [record]);
            }
            let joiner = [];
            for (let v of params) {
                joiner.push(Ext.isString(v) ? '\'' + v + '\'' : v);
            }
            text = Ext.String
                .format(
                    '<a href="javascript:" onclick="Ext.getCmp(\'{0}\').up(\'[controller]\').getController().{1}({2})">{3}</a>', //
                    view.getId(), column.fn, joiner.join(), text);
        }
        return text;
    }
});